﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cal2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str01 = Txt01.Text;
            string str00 = comboBox2.Text;
            string str02 = Txt02.Text;
            if (str01.Length == 0)
            {
                //第一种方式提示错误
                MessageBox.Show("第一个数没有输入有效的数字", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Txt01.Text = string.Empty;
                Txt01.Focus();
                return;
            }
            int num01 = Convert.ToInt32(str01);
            if (num01 < 0 || num01 > 1000)
            {
                MessageBox.Show("第一个数输入的数字必须介于0-1000之间", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Txt01.Text = string.Empty;
                Txt01.Focus();
                return;
            }
            if (str02.Length == 0)
            {
                //第一种方式提示错误
                MessageBox.Show("第二个数没有输入有效的数字", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Txt02.Text = string.Empty;
                Txt02.Focus();
                return;
            }
            int num02 = Convert.ToInt32(str02);
            if (num02 < 0 || num02 > 1000)
            {
                MessageBox.Show("第二个数输入的数字必须在0-1000之间", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Txt02.Text = string.Empty;
                Txt02.Focus();
                return;
            }
            //计算
            switch (str00)
            {
                case "+":
                    Txtresult.Text = (num01 + num02).ToString();
                    break;
                case "-":
                    Txtresult.Text = (num01 - num02).ToString();
                    break;
                case "*":
                    Txtresult.Text = (num01 * num02).ToString();
                    break;
                case "/":
                    Txtresult.Text = (num01 / num02).ToString();
                    break;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Txt01.Text = string.Empty;
            this.Txt02.Text = string.Empty;
            this.Txtresult.Text = string.Empty;
            this.Txt01.Focus();
        }
    }
}
